package com.hqyj.mall.xiaomimall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hqyj.mall.xiaomimall.entity.Address;
import com.hqyj.mall.xiaomimall.mapper.AddressMapper;
import com.hqyj.mall.xiaomimall.service.AddressService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.List;

@Service
public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> implements AddressService {

    @Resource
    private AddressMapper addressMapper;


    @Override
    public List<Address> queryAddressListByUid(Integer uid) {
        QueryWrapper<Address> queryWrapper = new QueryWrapper<Address>();
        queryWrapper.eq("uid",uid);
        return super.list(queryWrapper);
    }

    @Transactional(rollbackOn = Exception.class)
    @Override
    public boolean saveAddress(Address address) throws Exception {
        try {
            return super.save(address);
        } catch (Exception ex) {
            ex.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return false;
        }
    }
}
